#include <iostream>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include <numeric>
using namespace std;

int _547(vector<vector<int>> &isConnected)
{
    set<int> Node;
    int cnt = 0;
    stack<int> NodeConnect;
    for (int i = 0; i < isConnected.size(); i++)
    {
        if (Node.count(i) == 0)
        {
            cnt++;
            Node.insert(i);
        }
        NodeConnect.push(i);
        while (!NodeConnect.empty())
        {
            int cur=NodeConnect.top();
            NodeConnect.pop();
            for (int j = 0; j < isConnected[cur].size(); j++)
            {
                if(isConnected[cur][j]==1&&Node.count(j)==0)
                {
                    NodeConnect.push(cur);
                    NodeConnect.push(j);
                    Node.insert(j);
                    break;
                }
            }
        }
    }
    return cnt;
}

int main()
{
    vector<vector<int>> isConnected={{1,0,0},{0,1,0},{0,0,1}};
    cout <<_547(isConnected)<<flush;
    return 0;
}